package com.whyw.dorm.controller;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.whyw.dorm.service.DormStudentService;
import com.whyw.entity.DormStudent;
import com.whyw.entity.result.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;


import java.io.Serializable;
import java.util.List;

/**
 * 学生入住表(DormStudent)表控制层
 *
 * @author makejava
 * @since 2025-06-29 18:41:35
 */
@RestController
@RequestMapping("dormStudent")
public class DormStudentController  {
    /**
     * 服务对象
     */
    @Resource
    private DormStudentService dormStudentService;

    /**
     * 分页查询所有数据
     *
     * @param page 分页对象
     * @param dormStudent 查询实体
     * @return 所有数据
     */
    @GetMapping
    public Result selectAll(Page<DormStudent> page, DormStudent dormStudent) {
        return Result.success(this.dormStudentService.page(page, new QueryWrapper<>(dormStudent)));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public Result selectOne(@PathVariable Serializable id) {
        return Result.success(this.dormStudentService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param dormStudent 实体对象
     * @return 新增结果
     */
    @PostMapping
    public Result insert(@RequestBody DormStudent dormStudent) {
        return Result.success(this.dormStudentService.save(dormStudent));
    }

    /**
     * 修改数据
     *
     * @param dormStudent 实体对象
     * @return 修改结果
     */
    @PutMapping
    public Result update(@RequestBody DormStudent dormStudent) {
        return Result.success(this.dormStudentService.updateById(dormStudent));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    public Result delete(@RequestParam("idList") List<Long> idList) {
        return Result.success(this.dormStudentService.removeByIds(idList));
    }
}

